package com.xoa.controller.tiggerplugin;

import com.xoa.service.work.impl.WorkServiceImpl;
import com.xoa.util.CookiesUtil;
import com.xoa.util.DateFormat;
import com.xoa.util.JsonToProptyOrMapAndList;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 创建作者:   张勇
 * 创建日期:   2017/6/28 15:22
 * 类介绍  :
 * 构造参数:
 */
@Controller
@RequestMapping(value = "webService")
public class WebPluginTigger {
    private Logger logger = Logger.getLogger(WebPluginTigger.class);
    @Autowired
    WorkServiceImpl workService;


    @RequestMapping(value = "/webServiceTigger", produces = {"application/json;charset=UTF-8"}, method = RequestMethod.POST)
    public @ResponseBody
    ToJson webServiceTigger(@RequestBody String userToString,
                            HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        logger.info("进入服务器");
        Map<String, Object> maps = JsonToProptyOrMapAndList.returnMaps(userToString);
        logger.info(JsonToProptyOrMapAndList.returnMaps(userToString));
        logger.info("解析获取json数据");
//        ToJson toJson = workService.notifyNotice(maps.get("format").toString(), maps.get("fromId").toString(),
//                DateFormat.getDate((String)maps.get("sendTime")), maps.get("subject").toString(), maps.get("content").toString(), maps.get("toId2").toString(),
//                Integer.valueOf(maps.get("flowId").toString()), Integer.valueOf(maps.get("flowPrcs").toString()));
        return null;
    }


}
